'''
This is a small script uesed by developers only for testing purposes.
All features you need are in ipmsg package.
I've finished most features such as Text message,File/Folder transfer.
Note that the project has't been started so long, so be prepared to encounter
all kinds of bugs...
'''

''' Planning changes : use lstat, utime to get or set file's extra attributes '''

from ipmsg.ipmsg import *

files = ["test.py", "ipmsg"]

def main():
    mm = IPMsg(("", IPMSG_DEFAULT_PORT-1))
    #mm.send(("10.20.30.202", IPMSG_DEFAULT_PORT), IPMSG_BR_ENTRY, "", "")
    mm.send(("255.255.255.255", IPMSG_DEFAULT_PORT), IPMSG_BR_ENTRY, "", "")
    mm.eventLoop()
    time.sleep(1)
    h = mm.hostmgr.getByIndex(0)
    if not h:
        print "There is no host in your LAN currently"
        h = ("127.0.0.1", IPMSG_DEFAULT_PORT-1)
    #print "enter your message here(if sealed ,it should end with #)"
    while True:
        #mm.sendFile(h, "test", files)
        msg = raw_input(">")
        cmd = IPMSG_SENDMSG|IPMSG_SENDCHECKOPT
        if msg.endswith("#"):
            cmd |= IPMSG_SECRETOPT
        elif msg.endswith("$"):
            cmd |= IPMSG_SECRETOPT|IPMSG_PASSWORDOPT
        mm.send(h, cmd, msg, "")
    mm.closeSocket()
    

if __name__ == '__main__':
    main()
